package com.cskaoyan.controller.wxcontroller;

import com.cskaoyan.bean.chaosbean.cart.bo.WxCartAddBo;
import com.cskaoyan.bean.chaosbean.cart.bo.WxCartFastAddBo;
import com.cskaoyan.bean.chaosbean.cart.bo.WxCartUpdateBo;
import com.cskaoyan.bean.chaosbean.cart.vo.CartIndexVO;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.service.wxservice.CartWechatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 楚夏三分
 * @datetime 2023/1/2 14:54
 * @description: TODO:
 */
@RestController
@RequestMapping("wx/cart")
public class CartWeChatController {
    @Autowired
    CartWechatService cartWechatService;

    @RequestMapping("index")
    public BaseRespVo index(){
        CartIndexVO cartIndexVO =  cartWechatService.index();
        return BaseRespVo.ok(cartIndexVO);
    }

    @RequestMapping("add")
    public BaseRespVo addCart(@RequestBody WxCartAddBo wxCartAddBo) {
        //执行插入操作
        cartWechatService.addCart(wxCartAddBo);
        //执行查找购物车中数量的操作
        int goodscount = cartWechatService.getGoodsCount();
        return BaseRespVo.okYa(goodscount);
    }

    @RequestMapping("goodscount")
    public BaseRespVo getgoodscount() {
        int goodscount = cartWechatService.getGoodsCount();
        return BaseRespVo.okYa(goodscount);
    }

    @RequestMapping("fastadd")
    public BaseRespVo fastAdd(@RequestBody WxCartFastAddBo wxCartFastAddBo) {
        Integer data = cartWechatService.fastAdd(wxCartFastAddBo);
        return BaseRespVo.okYa(data);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody WxCartUpdateBo cartUpdateBo) {
        cartWechatService.update(cartUpdateBo);
        return BaseRespVo.ok("成功");
    }

}
